Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
The read-pkg npm package is used to read a package.json file and parse its contents. It can normalize the data according to the npm normalization rules, handle different file encodings, and can read from different locations by resolving the path to the nearest package.json file.
Read package.json from the current directory
This feature reads the package.json file from the current working directory and outputs the parsed JSON object.
const readPkg = require('read-pkg');
(async () => {
const pkg = await readPkg();
console.log(pkg);
})();
Read package.json from a specified directory
This feature allows you to specify a directory from which to read the package.json file, rather than the current working directory.
const readPkg = require('read-pkg');
(async () => {
const pkg = await readPkg({ cwd: 'path/to/directory' });
console.log(pkg);
})();
Read and normalize package.json data
This feature reads the package.json file and normalizes its data according to npm normalization rules, which can be useful for ensuring consistent data structure.
const readPkg = require('read-pkg');
(async () => {
const pkg = await readPkg({ normalize: true });
console.log(pkg);
})();
read-package-json is an npm package that reads the package.json file and also provides normalization. It is the library that npm itself uses to read package.json files, which means it's well-tested and reliable, but it might be more complex and tightly coupled with npm's internal use cases compared to read-pkg.
load-json-file is a package that provides a simple API for reading and parsing JSON files. It does not specifically target package.json files, so it lacks the normalization features of read-pkg, but it can be used for general JSON file reading purposes.
pkg-conf is a package that reads configuration from package.json files. It's focused on retrieving configuration settings rather than reading the entire package.json file, so it serves a slightly different purpose compared to read-pkg.
Read a package.json file
$ npm install --save read-pkg
const readPkg = require('read-pkg');
readPkg().then(pkg => {
console.log(pkg);
//=> {name: 'read-pkg', ...}
});
readPkg(__dirname).then(pkg => {
console.log(pkg);
//=> {name: 'read-pkg', ...}
});
readPkg(path.join('unicorn', 'package.json')).then(pkg => {
console.log(pkg);
//=> {name: 'read-pkg', ...}
});
Returns a Promise
for the parsed JSON.
Returns the parsed JSON.
Type: string
Default: .
Path to a package.json
file or its directory.
Type: boolean
Default: true
Normalize the package data.
package.json
fileMIT © Sindre Sorhus
FAQs
Read a package.json file
The npm package read-pkg receives a total of 30,163,416 weekly downloads. As such, read-pkg popularity was classified as popular.
We found that read-pkg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.